import requests as re
from bs4 import BeautifulSoup as bs
import tkinter as tk
from tkinter.filedialog import askdirectory
import urllib.request
import os


def get_html_soup(url):
    '''
    函数：根据网页返回soup对象
    '''
    r = re.get(url, timeout=30)
    s = bs(r.text, 'lxml')
    return s


def get_filepath(tag_name):
    '''
    获取文件存放地址
    '''
    print('选择文件保存位置')
    window = tk.Tk()
    window.withdraw()
    filepath = askdirectory(title=u'选择tag：《' + tag_name + '》的保存路径')
    while len(filepath) == 0:
        print('重新选择tag：《' + tag_name + '》的保存路径')
        filepath = askdirectory(title=u'选择tag：《' + tag_name + '》的保存路径')
    # print(filepath)
    return filepath


filepath = get_filepath('性感美女图片大全')
print(filepath)
